import sys
from pathlib import Path

base_path = str(Path(__file__).resolve().parent.parent)
sys.path.append(base_path)

from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from create_llm import create_llm

_prompt = ChatPromptTemplate.from_template("{user_content}")
# temp = _prompt.invoke("你好，你是谁")
# temp = _prompt.invoke({"user_content": "你好，你是谁"})
# print(temp)

_llm = create_llm("deepseek")
# print(_llm)

_parser = StrOutputParser()
# print(_parser)

# temp = _parser.stream(_llm.invoke(_prompt.invoke({"user_content": "你好，你是谁"})))
# chat = _prompt | _llm | _parser
# temp = chat.invoke("你好，你是谁")
# print(temp)


chat = _prompt | _llm | _parser
for chunk in chat.stream({"user_content": "你好，你是谁"}):
    print(chunk, end="", flush=True)

temp = _prompt.invoke("你好，你是谁")
# temp = _llm.invoke(temp)
# for chunk in _parser.stream(temp):
#     print(chunk, end="", flush=True)
